package com.wiscamp.ninechapters;

import com.wiscamp.ninechapters.common.rest.RestResponse;
import jakarta.security.auth.message.AuthException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

@Provider
public class AuthExceptionMapper implements ExceptionMapper<AuthException> {

    @Override
    public Response toResponse(AuthException exception) {
        RestResponse<String> restResponse = new RestResponse<>();
        restResponse.setCode("general-exception.authentication");
        restResponse.setMessage(exception.getMessage());
        restResponse.setData("");
        return Response.ok(restResponse).build();
    }
}
